#ifndef _DATABASE_MYSQL_H_
#define _DATABASE_MYSQL_H_

#include <mysql/mysql.h>
#include <string>
#include <vector>

using namespace std;

class DbInfo
{
public:
    DbInfo(): port(3306){}
public:
    string host;
    unsigned int port;
    string username;
    string passwd;
    string dbname;
};

class CMysql
{
public:
	CMysql();
	~CMysql();

	bool Connect(const DbInfo &dbinfo);	

	void Close();  

	inline bool Execute(const string &sql)
        { return Execute(sql.c_str(), sql.length()); }

	bool Execute(const char* sql, size_t len);

        bool FetchRow(vector<string> &row);

        inline string ErrorMsg()
        { return  mysql_error(m_mysql_handle); }

        string EscapeString(const string &src);

private:	               
	void FreeResult();
	bool SetNames(const char* encode);

private:
	MYSQL       *m_mysql_handle;	
	MYSQL_RES   *m_query_result;

	bool        m_isconnected;
};

#endif //_DATABASE_MYSQL_H_

